﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;

namespace Hi_Baidu.Net
{
    public class SystemUdpPortListener : UdpPortListener
    {
        private MessageListener messageListener;
        public SystemUdpPortListener(int Port, MessageListener messageListener, String Key)
            : base(Port, messageListener, Key)
        {
            this.messageListener = messageListener;
        }

        public override void Init()
        {
            this.PortProcessor = new UdpClient(this.Port);
            ((SystemUdpMessageListener) this.messageListener).Udpclient = this.PortProcessor;
            this.messageListener.Init();
        }

        public override void Dispose()
        {
            if (this.PortProcessor != null)
            {
                 this.PortProcessor.Close();
            }
            if (this.CurrentThread != null)
            {
                this.CurrentThread.Abort();
            }
        }
    }
}
